package com.ruyuan.commodity.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruyuan.commodity.model.goods.dos.BrandDO;
import com.ruyuan.commodity.model.goods.vo.SelectVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 品牌BrandDO的Mapper
 */
@Repository
public interface BrandMapper extends BaseMapper<BrandDO> {

    /**
     * 查询某分类下的品牌
     *
     * @param categoryId 分类id
     * @return
     */
    @Results({
            @Result(column = "brand_id", property = "brandId", id = true),
            @Result(column = "name", property = "name"),
            @Result(column = "logo", property = "logo"),
    })
    @Select("select b.brand_id,b.`name`,b.logo from es_category_brand cb " +
            "inner join es_brand b on cb.brand_id=b.brand_id " +
            "where cb.category_id=#{category_id} and b.disabled = 1")
    List<BrandDO> getBrandsByCategory(@Param("category_id") Long categoryId);

    /**
     * 查询分类品牌，所有品牌，分类绑定的品牌为已选中状态
     *
     * @param categoryId 分类id
     * @return
     */
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "name", property = "text"),
            @Result(column = "category_id", property = "falgid"),
    })
    @Select("select b.brand_id id , cb.category_id falgid  , b.`name` `text` " +
            "from es_brand b left join  es_category_brand cb on b.brand_id=cb.brand_id and category_id = #{category_id} " +
            "where b.disabled=1")
    List<SelectVO> getCatBrand(@Param("category_id") Long categoryId);

}
